from flask.ext.classy import FlaskView, request, route

from ..schema.resp import query_schema, account_his_list
from ..schema.error import LOCAL_AUTH_NOT_EXIST
from ..services.account import AccountService


class AccountView(FlaskView):
    @route('/<account_id>/history', methods=['GET'])
    def get_accout_historys(self, account_id):
        account = AccountService.get_account_by_id(account_id)
        if account:
            account_his, pagination = AccountService.get_account_his_by_id(account_id)
        else:
            return LOCAL_AUTH_NOT_EXIST.jsonify()
        if account_his:
            return query_schema.jsonify_with(
                items=account_his_list.dump(account_his).data
            )
